package io.renren.modules.lanling.service.impl;

import io.renren.modules.lanling.entity.QuestionEntity;
import io.renren.modules.lanling.entity.StuSubEntity;
import io.renren.modules.lanling.service.QuestionService;
import io.renren.modules.lanling.service.StuSubService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.Query;

import io.renren.modules.lanling.dao.QuestionRecordDao;
import io.renren.modules.lanling.entity.QuestionRecordEntity;
import io.renren.modules.lanling.service.QuestionRecordService;


@Service("questionRecordService")
public class QuestionRecordServiceImpl extends ServiceImpl<QuestionRecordDao, QuestionRecordEntity> implements QuestionRecordService {

    @Autowired
    private QuestionService questionService;

    @Override
    public PageUtils queryPage(Map<String, Object> params) {

        //自定义分页列表
        Query query = new Query(params);
        List<QuestionRecordEntity> QuestionRecordEntityList = this.baseMapper.queryList(query);
        Integer total = this.baseMapper.queryTotal(query);

        return new PageUtils(QuestionRecordEntityList, total, query.getLimit(), query.getCurrPage());
    }

    /**
     * 判断题目答案是否正确
     *
     * @param stuAnster
     * @param trueAnster
     * @return
     */
    @Override
    public boolean cheakAnster(String stuAnster, String trueAnster) {
        if (stuAnster != null && stuAnster != "" && trueAnster != null && trueAnster != "") {
            if (stuAnster == trueAnster) {
                return true;
            } else {
                return false;
            }
        }
        return false;
    }

    @Override
    public void delQuestionRecordByUser(int subjectId, int studentId) {
        this.baseMapper.delQuestionRecordByUser(subjectId, studentId);
    }

    @Override
    public void deleteByUserId(long studentId) {
        this.baseMapper.deleteByUserId(studentId);
    }
}
